package com.atguigu.gmall.product.controller;



import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.mapper.SkuInfoMapper;
import io.swagger.annotations.Api;
import com.atguigu.gmall.product.service.levelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.configurationprocessor.json.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.nio.file.ProviderNotFoundException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/product")
@Api(tags = "商品对外接口")
public class ProductApiController {

    @Autowired
    private levelService levelService;

    //    1、根据skuId查询sku_info  根据skuId查询sku_image  /inner：内部资源
    @GetMapping("inner/getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable("skuId") Long skuId){
        SkuInfo skuInfo = levelService.getSkuInfo(skuId);
        return skuInfo;
    }

    //2:查询实时价格   优化的时候 不要放进缓存中
    @GetMapping("inner/getPrice/{skuId}")
    public BigDecimal getPrice(@PathVariable("skuId") Long skuId){
        return levelService.getPrice(skuId);
    }

    //3、根据category3Id查询一二三级分类
    @GetMapping("inner/getCategoryView/{category3Id}")
    public BaseCategoryView getCategoryView(@PathVariable("category3Id") Long category3Id){
        BaseCategoryView baseCategoryView =
                levelService.getCategoryView(category3Id);
        return baseCategoryView;
    }

    //4、根据spuId查询spu_sale_attr_value(被选中项）  商品ID spu  库存ID
    @GetMapping("inner/getSpuSaleAttrValue/{spuId}/{skuId}")
    public List<SpuSaleAttr> getSpuSaleAttrValue(@PathVariable("spuId") Long spuId,
                                                 @PathVariable("skuId") Long skuId){
        return levelService.getSpuSaleAttrValue(skuId,spuId);
    }

    //5、skuId与销售属性组合
    @GetMapping("/inner/spuValueIdsMap/{spuId}")
    public Map spuValueIdsMap(@PathVariable("spuId") Long spuId){
        return levelService.spuValueIdsMap(spuId);
    }

    //首页商品分类实现
    @GetMapping("/inner/getBaseCategoryList")
    public List<BaseCategoryView> getBaseCategoryList(){
        return levelService.getBaseCategoryList();
    }

    //查询品牌
    @GetMapping("/inner/getBaseTrademarkById/{tmId}")
    public BaseTrademark getBaseTrademarkById(@PathVariable Long tmId){
        return levelService.getBaseTrademarkById(tmId);
    }

    //根据skuId 查询平台属性及属性值
    @GetMapping("/inner/getSkuAttrValueList/{skuId}")
    public List<SkuAttrValue> getSkuAttrValueList(@PathVariable Long skuId){
        return levelService.getSkuAttrValueList(skuId);
    }
}
